﻿using System;
using System.IO;
using System.Net;
using System.Text.RegularExpressions;

namespace LuckyCoding.Models;

public class WebFileModel : IFileModel
{
    public string? FileName { get; set; }
    public string? Location { get; set; }
    
    public WebFileModel(){}

    [Obsolete("得用HttpClient了")]
    public WebFileModel(string url)
    {
        Location = url;
        WebClient x = new WebClient();
        string source = x.DownloadString(url);
        FileName = Regex.Match(source, @"\<title\b[^>]*\>\s*(?<Title>[\s\S]*?)\</title\>",
            RegexOptions.IgnoreCase).Groups["Title"].Value;
    }
    
    public override string ToString()
    {
        return FileName!;
    }
}